package com.itheima.advance.reflect.demo03;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class ReflectDemo02 {

    public static void main(String[] args) throws Exception {

        Class<?> studentClass = Class.forName("com.itheima.advance.reflect.demo03.Student");

        Field nameField = studentClass.getDeclaredField("name");

        Constructor<?> declaredConstructor = studentClass.getDeclaredConstructor();
        Student student = (Student) declaredConstructor.newInstance();
        nameField.set(student, "蓝湛");
        student.show();

        Student student1 = (Student) studentClass.newInstance();
        nameField.set(student1, "魏婴");
        student1.show();

        Field ageField = studentClass.getDeclaredField("age");
        ageField.setAccessible(true);
        ageField.set(student, 15);
        student.show();
        ageField.set(student1, 14);
        student1.show();
    }
}
